<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>授权钥匙</title>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    
    <link href="${pageContext.request.contextPath}/static/css/common.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/css/bootstrap.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/font-awesome-4.3.0/css/font-awesome.min.css"
          rel="stylesheet">
    <!-- jqgrid-->
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/custom.ui.jqgrid.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/layer/skin/layer.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/style.css" rel="stylesheet">

    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/jquery.form.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/common.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/i18n/grid.locale-cn.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/minified/jquery.jqGrid.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/layer/layer.js" type="text/javascript"></script>
 	<script src="${pageContext.request.contextPath}/static/js/global.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/static/plugins/My97DatePicker/WdatePicker.js"></script>
    <style type="text/css">
        .main h5 a {
            position: absolute;
            right: 20px;
            font-size: 14px;
            bottom: 0px;
            display: inline-block;
            padding: 5px;
        }

        .table_list tbody tr {
            height: 35px;
            text-align: center;
        }
        .tab{
        	border: solid #DDDDDD;
    		border-width: 1px 1px 1px 1px;
   			width: 100%;
    		margin-top: 10px !important;
        }
    </style>
</head>
<body>
<div class="col-sm-12">
   <div class="jqGrid_wrapper">
            <h1>单元门禁</h1>
        <table id="jqGrid" style="font-size: 12px !important;"></table>
            <h1>公共门禁（*勾选楼栋门时，默认配发公共门禁）</h1>
        <table id="jqGrid1" style="font-size: 12px !important;"></table>
        <h1>设置钥匙有效期</h1>
        <table id="previewTable" class="tab" style="text-align: center;height: 50px;" >
        	<tr>
	           		<td style="width: 132px;">钥匙有效期至:</td>
	           		<td > <input class="form-control" name="validity" id='validity' style="width: 185px;"
                   onclick='WdatePicker()'/></td>
	           </tr>
        </table>
<!--         	<label style="float: left;">钥匙有效期至：</label> -->
<!--             <input class="form-control" name="validity" id='validity' style="width: 185px;" -->
<!--                    onclick='WdatePicker()'/> -->
        <a id="sure" onclick="sure()" hidden="true">first</a>
        <input type="hidden" id="sid" value="${sid}"/>
    </div>
</div>
<script type="text/javascript">
$(document).ready(
        function () {
        	$.jgrid.defaults.styleUI = "Bootstrap";
            $("#jqGrid").jqGrid(
                    {
                        url: "${pageContext.request.contextPath}/admin/tlocks_tlockList.action?type=private&communityId=${communityId}",
                        mtype: 'POST',
                        datatype: "json",
                        height:140,
                        autowidth: true,
                        shrinkToFit: true,
                        rowNum: -1,
                        colNames: ['序号', '门禁名称', '类型'],
                        colModel: [{
                            name: "SID",
                            index: "SID",
                            key: true,
                            hidden: true
                        }, {
                            name: 'INSTALLLOCKNAME',
                            index: 'INSTALLLOCKNAME'
                        }, {
                            name: '',
                            index: '',
                            formatter: function () {
                                return '单元门禁';
                            }
                        }],
                        sortname: 'sid',
                        rownumbers: true,
                        jsonReader: {
                            root: 'rows',
                            page: "page",
                            total: 'total',
                            records: "records",
                            repeatitems: false
                        },
                        pager: "#jqGrid_paper",
                        viewrecords: true,
                        multiselect: true,
                        hidegrid: false
                    });
            $("#jqGrid1").jqGrid(
                    {
                        url: "${pageContext.request.contextPath}/admin/tlocks_tlockList.action?type=share&communityId=${communityId}",
                        mtype: 'POST',
                        datatype: "json",
                        height:100,
                        autowidth: true,
                        shrinkToFit: true,
                        rowNum: -1,
                        colNames: ['序号', '门禁名称', '类型'],
                        colModel: [{
                            name: "SID",
                            index: "SID",
                            key: true,
                            hidden: true
                        }, {
                            name: 'INSTALLLOCKNAME',
                            index: 'INSTALLLOCKNAME'
                        }, {
                            name: '',
                            index: '',
                            formatter: function () {
                                return '公共门禁';
                            }
                        }],
                        sortname: 'sid',
                        rownumbers: true,
                        jsonReader: {
                            root: 'rows',
                            page: "page",
                            total: 'total',
                            records: "records",
                            repeatitems: false
                        },
                        pager: "#jqGrid_paper",
                        viewrecords: true,
                        multiselect: true,
                        hidegrid: false,
                        loadComplete: function () {
                        	$("#cb_jqGrid1").click();
                        }
                    });
            $(".ui-jqgrid-htable").attr("style","font-size: 12px !important;");
            var date = new Date();
            var seperator1 = "-";
            var year = date.getFullYear()+1;
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            var currentdate = year + seperator1 + month + seperator1 + strDate;
            $("#validity").val(currentdate);
		
        });
        function sure(){
        	var prvId = jQuery("#jqGrid").jqGrid('getGridParam', 'selarrrow');
        	var pubId = jQuery("#jqGrid1").jqGrid('getGridParam', 'selarrrow');
        	var sid = $("#sid").val();
        	var roomstatus = $("#sid").val();
        	var validity = $("#validity").val();
        	$.post("${pageContext.request.contextPath}/admin/tusers_audit.action?prvId="+prvId+"&pubId="+pubId, {
        		'sid': sid,
        		'validity':validity,
        		'communityId':'${communityId}',
       	   		'agtCode':'${agtCode}',
        		'roomStatus':'${roomStatus}',
    	   		'status': 1
             }, function (result) {
            	 data = JSON.parse(result);
                 window.parent.layer.closeAll('loading'); 
                 if (data.code == 1) {
                     layer.alert(data.msg, function () {
                    	 window.parent.layer.closeAll(); 
                    	 window.parent.refreshGrid();
                    	 });
                 }else{
                	$("#sure").html("first");
                 	layer.alert(data.msg);
                 }
             });
        }
</script>
</body>
</html>
